//
//  HMBaseTabBarViewController.swift
//  sinaweibo
//
//  Created by WGP on 16/4/8.
//  Copyright © 2016年 WGP. All rights reserved.
//

import UIKit

class HMBaseTabBarViewController: UITableViewController {
    
//    用户是否登录
    var userLogin = HMUserAccountViewModel.sharedInstance.userLogin
    
    override func loadView() {
        userLogin ? super.loadView() : setupVisitorView()
    }
    
//    MARK: - 添加访客视图
    private func setupVisitorView()
    {
       view =  visitorView
        
        view.backgroundColor = UIColor(white: 237/255.0, alpha: 1)
        
        visitorView.delegate = self
        
        if self is HMHomeTableViewController
        {
//            控制器不在当前window就会默认动画结束,所以动画结束后不要移除
            
            visitorView.startRotation()
        }else if self is HMMessageTableViewController
        {
            visitorView.setupVisitorViewContent("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }else if self is HMDisconverTableViewController
        {
            visitorView.setupVisitorViewContent("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is HMProfileTableViewController
        {
            visitorView.setupVisitorViewContent("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
//        设置导航条按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: Selector("visitorViewDidClickRegisterBtn"))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: Selector("visitorViewDidClickLoginBt"))
    }
    

    
//    MARK: - 懒加载
    lazy var visitorView: HMVisitorView = HMVisitorView()

}

//类拓展
extension HMBaseTabBarViewController:HMVisitorViewDelegate
{
    
    //    MARK: - 代理方法
    func visitorViewDidClickLoginBt() {
//        HMPrint("visitorViewDidClickLoginBt")
        let nav = UINavigationController(rootViewController: HMOauthViewController())
        presentViewController(nav, animated: true, completion: nil)
    }
    
    func visitorViewDidClickRegisterBtn() {
//        HMPrint("visitorViewDidClickRegisterBtn")
        dismissViewControllerAnimated(true, completion: nil)
    }
}








